package com.example.demo2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo2.common.Result;
import com.example.demo2.entity.PcConfig;
import com.example.demo2.service.AddressCountyService;
import com.example.demo2.service.OrderService;
import com.example.demo2.service.PcConfigService;
import com.example.demo2.service.ShopPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pcConfig")
public class PcConfigController {
    @Autowired
    private PcConfigService pcConfigService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private AddressCountyService addressCountyService;
    @Autowired
    private ShopPlaceService shopPlaceService;

    @GetMapping("/info")
    public Result info() {
        LambdaQueryWrapper<PcConfig> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PcConfig::getId, 1);
        PcConfig one = pcConfigService.getOne(lqw);
        int orderNum = orderService.list().size();
        one.setSumOrder(String.valueOf(orderNum));
        int cityNum = addressCountyService.list().size();
        one.setSumCity(String.valueOf(cityNum));
        int shopNum = shopPlaceService.list().size();
        one.setSumShop(String.valueOf(shopNum));
        pcConfigService.updateById(one);
        return Result.success(one);
    }

    @PostMapping("/updata")
    public Result updata(@RequestBody PcConfig pcConfig) {
        boolean b = pcConfigService.updateById(pcConfig);
        return Result.success(b);
    }


}
